package com.lili.setting.controller;

import com.lili.common.result.Result;
import com.lili.model.setting.AdminUser;
import com.lili.model.setting.vo.AdminUserSearchParam;
import com.lili.setting.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 用户信息管理
 */
@RestController
@RequestMapping("/admin/setting/user")
public class UserController {

    @Autowired
    private UserService userService;


    @GetMapping("/get")
    public Result getAllUser() {
        List<AdminUser> list = userService.getAllUser();
        return Result.ok(list);
    }


    /**
     * 添加用户
     *
     * @param adminUser
     * @return
     */
    @PostMapping("/save")
    public Result saveUser(@RequestBody AdminUser adminUser) {

        userService.saveUser(adminUser);

        return Result.ok();
    }

    /**
     * 根据id修改用户的状态
     *
     * @param userId
     * @param status
     * @return
     */
    @PutMapping("/status/{userId}")
    public Result changeStatus(@PathVariable String userId, boolean status) {
        userService.changeStatus(userId, status);
        return Result.ok();
    }

    /**
     * 根据id 删除用户
     *
     * @param userId
     * @return
     */
    @DeleteMapping("/delete/{userId}")
    public Result deleteUserById(@PathVariable String userId) {

        userService.deleteUser(userId);

        return Result.ok();
    }


    /**
     * 更新用户信息
     *
     * @param adminUser
     * @return
     */
    @PutMapping("/edit")
    public Result editUser(@RequestBody AdminUser adminUser) {
        userService.editUser(adminUser);

        return Result.ok();
    }

    /**
     * 分页查询用户角色
     *
     * @param adminUserSearchParam
     * @return
     */
    @GetMapping("/page")
    public Result getUserPageInfo(AdminUserSearchParam adminUserSearchParam) {

        Map map = userService.getUserPageInfo(adminUserSearchParam);

        return Result.ok(map);
    }


}
